package com.gyms.manager;

import android.content.Context;
import android.content.Intent;

import com.classic.okhttp.beans.HVClickInfoBean;
import com.classic.okhttp.enums.Enum;
import com.gyms.activity.CodeLoginActivity;
import com.gyms.activity.GymDetailActivity;
import com.gyms.activity.ProductDetailsActivity;
import com.gyms.activity.SeatChoseActivity;
import com.gyms.constant.Constants;

/**
 * 广告跳转处理类
 * Created by 小俞 on 2016/12/22 0022.
 */
public class BannerIntentManger {
    private AndroidJavaScript script;
    private Context mContext;

    public BannerIntentManger(Context context) {
        script = new AndroidJavaScript(context);
        this.mContext= context;
    }

    /**
     * 跳转处理方法
     *
     * @param action 点击的类型
     * @param ids     String gymId,String projectId,int time
     */
    public void bannerIntent(HVClickInfoBean clickInfo, Enum.EnumHomepageAction action, String title, String... ids) {
        if(clickInfo==null){
            return;
        }
        if(clickInfo.getRequireLogin()){//检查是否需要登录
            if(!DataCenter.getInstance().checkIsLogin()){//检查是否登录
                Intent mIntent=new Intent(mContext,CodeLoginActivity.class);
                mContext.startActivity(mIntent);
                return;
            }
        }
        switch (action) {
            case Innerh5://软件浏览器H5
                script.showWebView(ids[0], title);
                break;
            case Outerh5://系统浏览器H5
                script.showSystemWeb(ids[0]);
                break;
            case Venuedetail://场馆详情
                String mGymId=ids[0];
                Intent mIntent = new Intent(mContext, GymDetailActivity.class);
                mIntent.putExtra(Constants.FLAG_INTENT_VENUEID, mGymId);
                mContext.startActivity(mIntent);
                break;
            case Productdetail://产品详情
//                script.showCourse(ids[0]);
                String mCourseId = ids[0];
                mIntent = new Intent(mContext, ProductDetailsActivity.class);
                mIntent.putExtra(Constants.FALG_INTENT_PRPDUCT_ID, mCourseId);
                mContext.startActivity(mIntent);
                break;
            case Itemselect://跳转到场馆指定页面
                if (ids.length >= 3) {//防止数组越界
//                    script.showVenueBooking(ids[0], ids[1], Integer.parseInt(ids[2]));
                    String gymId = ids[0];
                    String projectId = ids[1];
                    int time = Integer.parseInt(ids[2]);
                    mIntent = new Intent(mContext, SeatChoseActivity.class);
                    mIntent.putExtra(Constants.FLAG_INTENT_VENUEID, gymId);
                    mIntent.putExtra(Constants.FLAG_INTENT_PROJECT_ID, projectId);
                    mIntent.putExtra(Constants.FLAG_INTENT_CHOSE_TIME, time);
                    mContext.startActivity(mIntent);
                }
                break;
        }
    }
}
